<?php
class User_reg extends CI_controller
{

    public function index()
    {
        //print_r($_POST);
        if ($_POST && $_POST['register'] == "提交") {
            //获取表单提交的数据
            $username = trim($_POST["username"]);
            $password = trim($_POST["password"]);
            $md5_passwd = md5($password);
            $password2 = trim($_POST["password2"]);
            $md5_passwd2 = md5($password2);
            $email = trim($_POST['email']);


            if ($username == "") {
                echo("昵称不能为空");
                exit;
            }
            if ($password == "") {
                echo("密码不能为空");
                exit;
            }
            if($md5_passwd!=$md5_passwd2){
                echo("两次密码输入不一致");
                exit;
            }


            $this->load->model('User_mod');
            $id = $this->User_mod->add_user($username,$md5_passwd,$email);
            if($id){
                $this->load->view('user_info');
            }
        }else{
            $this->load->view('user_reg');
        }
    }

    function reg(){
        $this->load->view('user_reg');
    }


    function ajax_reg(){
        $username = $this->input->post('name');
        $this->load->model('user_mod');
        $res = $this->user_mod->getUser(array('username'=>$username));

        if($res){
            // echo 1;
            $rs = array(
                'error' => 1,
                'msg' => "用户已存在"
            );
        }else{
            $rs = array(
                'error' => 0,
                'msg' => "用户可以使用"
            );
        }

        echo json_encode($rs);exit;
    }


}

?>
